package com.ffdms.mobileoffice;

import java.util.List;

import com.ffdms.mobileoffice.MessageAdapter.ViewHolder;
import com.ffdms.service.MessageDigest;
import com.ffdms.util.MobileOfficeUtil;
import com.ffdms.vo.Notice;
import com.ffdms.vo.ProjectInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ProjectListAdapter extends BaseAdapter {
	private Context context;
	private List<ProjectInfo> projects;

	public ProjectListAdapter(Context context, List<ProjectInfo> projects) {
		this.context = context;
		this.projects = projects;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.projects.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.projects.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.project_item_view, null);
			holder = new ViewHolder();
			holder.tv_project_title = (TextView) convertView
					.findViewById(R.id.tv_project_title);
			holder.tv_project_time = (TextView) convertView
					.findViewById(R.id.tv_project_time);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (projects != null) {
			ProjectInfo project = projects.get(position);
			holder.tv_project_title.setText(project.getName());
			String d = MobileOfficeUtil.formatDate("MM月dd日",
					project.getModifyTime());
			holder.tv_project_time.setText(d);
		}
		return convertView;
	}

	static class ViewHolder {
		TextView tv_project_title;
		TextView tv_project_time;
	}

}
